package com.leonzx.base.config.datasource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * Created by liang on 2018/3/28.
 */
public class DynamicDataSource extends AbstractRoutingDataSource {

    private final static Logger logger = LoggerFactory.getLogger(DynamicDataSource.class);

    @Override
    protected Object determineCurrentLookupKey() {
        logger.info("数据源为{}", DataSourceContextHolder.getDB() == null ? "默认数据源" : DataSourceContextHolder.getDB());
        return DataSourceContextHolder.getDB();
    }
}
